*** Settings ***
Documentation     CaseName: 信息监控中-设备监控-AP,MAC地址过滤功能正常
...               Auther: wangll
...               编写日期: 2019-8-05
Suite Setup       初始化操作
Suite Teardown    恢复配置并退出
Force Tags         ar3_Ap_0230  ar3_AP_Monitor_0090     信息监控  设备监控  AP   双频AP
Resource          common_proc.txt
Test Setup        Run Keyword If  "${PREV TEST STATUS}"=="FAIL"  Fail  terminate test suite execute for above fails
Test Timeout      15 minutes

*** Variables ***
${group_name}         auto_test
${Aptemplate_name}    auto_test_A
${ap_name}          AP

*** Test Cases ***
Step1: 添加上线AP设备，分组，AP模板
    [Setup]    No Operation
    增添能在AR3上线AP设备并检查是否增加成功  ${AP_Mac}  ${AP_SN}  ${ap_name}_1
    ${group_id}    增加AP分组  ${group_name}
    ${Aptemplate_id}    增加AP默认配置的模板    ${Aptemplate_name}
    Set Suite Variable  ${group_id}
    Set Suite Variable  ${Aptemplate_id}

    LOG   移动设备到分组中
    ${mac}    Set Variable  ${AP_Mac}
    ${ret}  移动设备到指定分组中  ${mac}   ${group_id}
    Check_Return_Value  ${ret}  true
    ${ret}  查询AP分组   group_name=${group_name}
    ${count}          find_pattern_from_string  '${ret}'  "name":"${group_name}","count":(\\d+)  0
    Should Be True   '${count}' == '${1}' 

Step2: 增加默认模板,SSID功能正常下发到AP
    ${rule_id}  增加配置同步规则   ${Aptemplate_id}  ${group_id}
    点击配置同步下发  ${rule_id}
    sleep  10s
    Set Suite Variable  ${rule_id}
    ${ip}   Wait Until Keyword Succeeds   60s  2s  在设备监控中查看APIP  ${AP_Mac}
    Set Suite Variable  ${ip}
    LOG    检查默认模板配置正常
    connect_to_ap  ap  ${ip}  
    Wait Until Keyword Succeeds   20s  2s   在AP后台检查wlan口  ap  ${2.4wlan0}  ${2.4wlan0}\\s+Link
    Wait Until Keyword Succeeds   20s  2s   在AP后台检查wlan口  ap  ${5wlan0}  ${5wlan0}\\s+Link
    
Step3: 查看射频参数默认是否正确
    修改AP模板中SSID参数  templateId=${Aptemplate_id}  ssidType=${2}  ssidNum=${1}  ssidName=${2.4G_ssid}_${1} 
    修改AP模板中SSID参数  templateId=${Aptemplate_id}  ssidType=${5}  ssidNum=${1}  ssidName=${5G_ssid}_${1} 
    点击配置同步下发  ${rule_id}
    Wait Until Keyword Succeeds   20s  2s   在信息监控-设备监控-AP查看SSID配置是否正确   AP_Mac=${AP_Mac}  ssid=${2.4G_ssid}_${1} 
    Wait Until Keyword Succeeds   20s  2s   在信息监控-设备监控-AP查看SSID配置是否正确   AP_Mac=${AP_Mac}  ssid=${5G_ssid}_${1}  wifimode=5g

Step4: 默认MAC地址过滤功能关闭状态并没有用户MAC存在 
    LOG   默认为关闭状态并没有MAC地址存在
    Wait Until Keyword Succeeds   20s  2s   在信息监控-设备监控-AP查看MAC过滤功能是否正确  AP_Mac=${AP_Mac}

Step5: 增加STAmac并开启MAC过滤白名单
    @{mac_list}  Create List
    ${stamac}     编辑MAC过滤     ${top_STA1_mac}
    Append To List    ${mac_list}   ${stamac} 
    在信息监控-设备监控-AP配置MAC地址过滤    AP_Mac=${AP_Mac}   macList=${mac_list}  macFilterEn=YES

    Wait Until Keyword Succeeds   20s  2s   在信息监控-设备监控-AP查看MAC过滤功能是否正确  AP_Mac=${AP_Mac}  macFilterEn=YES  maclist=${top_STA1_mac}  wlMacRule=${1}
    sleep  10s
    Wait Until Keyword Succeeds   2x  5s   STA关联SSID并检查地址和访问外网    ssid=${2.4G_ssid}_${1}
    Wait Until Keyword Succeeds   2x  5s   STA关联SSID并检查地址和访问外网    ssid=${5G_ssid}_${1}

Step6: 开启MAC过滤黑名单
    @{mac_list}  Create List
    ${stamac}     编辑MAC过滤     ${top_STA1_mac}
    Append To List    ${mac_list}   ${stamac} 
    在信息监控-设备监控-AP配置MAC地址过滤    AP_Mac=${AP_Mac}   macList=${mac_list}  macFilterEn=YES  wlMacRule=${2}

    Wait Until Keyword Succeeds   20s  2s   在信息监控-设备监控-AP查看MAC过滤功能是否正确  AP_Mac=${AP_Mac}  macFilterEn=YES  maclist=${top_STA1_mac}  wlMacRule=${2}
    sleep  10s
    Run Keyword And Expect Error  connect ${2.4G_ssid}_${1} fail   手机关联SSID   ssid=${2.4G_ssid}_${1}   Encryption_mode=open
    Run Keyword And Expect Error  connect ${5G_ssid}_${1} fail   手机关联SSID   ssid=${5G_ssid}_${1}   Encryption_mode=open

Step7: 关闭mac过滤功能
    @{mac_list}  Create List
    ${stamac}     编辑MAC过滤     ${top_STA1_mac}
    Append To List    ${mac_list}   ${stamac} 
    在信息监控-设备监控-AP配置MAC地址过滤    AP_Mac=${AP_Mac}   macList=${mac_list}  macFilterEn=NO  wlMacRule=${2}

    Wait Until Keyword Succeeds   20s  2s   在信息监控-设备监控-AP查看MAC过滤功能是否正确  AP_Mac=${AP_Mac}  macFilterEn=NO  maclist=${top_STA1_mac}  
    sleep  10s
    Wait Until Keyword Succeeds   2x  5s   STA关联SSID并检查地址和访问外网    ssid=${2.4G_ssid}_${1}
    Wait Until Keyword Succeeds   2x  5s   STA关联SSID并检查地址和访问外网    ssid=${5G_ssid}_${1}

Step8: 开启MAC过滤黑名单
    @{mac_list}  Create List
    ${stamac}     编辑MAC过滤     ${top_STA1_mac}
    Append To List    ${mac_list}   ${stamac} 
    在信息监控-设备监控-AP配置MAC地址过滤    AP_Mac=${AP_Mac}   macList=${mac_list}  macFilterEn=YES  wlMacRule=${2}

    Wait Until Keyword Succeeds   20s  2s   在信息监控-设备监控-AP查看MAC过滤功能是否正确  AP_Mac=${AP_Mac}  macFilterEn=YES  maclist=${top_STA1_mac}  wlMacRule=${2}
    sleep  10s
    Run Keyword And Expect Error  connect ${2.4G_ssid}_${1} fail   手机关联SSID   ssid=${2.4G_ssid}_${1}   Encryption_mode=open
    Run Keyword And Expect Error  connect ${5G_ssid}_${1} fail   手机关联SSID   ssid=${5G_ssid}_${1}   Encryption_mode=open
    
Step9: 删除MAC过滤MAC地址
    @{mac_list}  Create List
    在信息监控-设备监控-AP配置MAC地址过滤    AP_Mac=${AP_Mac}   macList=@{mac_list}  macFilterEn=YES  wlMacRule=${2}

    Wait Until Keyword Succeeds   20s  2s   在信息监控-设备监控-AP查看MAC过滤功能是否正确  AP_Mac=${AP_Mac}  macFilterEn=YES   wlMacRule=${2}
    sleep  10s
    Wait Until Keyword Succeeds   2x  5s   STA关联SSID并检查地址和访问外网    ssid=${2.4G_ssid}_${1}
    Wait Until Keyword Succeeds   2x  5s   STA关联SSID并检查地址和访问外网    ssid=${5G_ssid}_${1}



*** Keywords ***
初始化操作
    ${login_TK}     登录云平台
    Set Suite Variable  ${login_TK}

恢复配置并退出
    close_connect_ap  ap
    在设备监控中解绑AP设备  ${AP_Mac} 
    在设备监控中查看AP设备     ${AP_Mac}  ${AP_SN}  false
    删除配置同步规则    ${rule_id}
    删除AP分组  ${group_id}
    删除AP模板      ${Aptemplate_id} 
    退出星云平台   ${login_TK}

编辑MAC过滤
    [Arguments]  ${stamac} 
    &{data} =  Create Dictionary
    ...  mac=${stamac}
    ...  name=${EMPTY}
    [Return]  ${data}

在信息监控-设备监控-AP配置MAC地址过滤
    [Arguments]  &{mac_filter}
    ${AP_Mac}    Set Variable If   "AP_Mac" in ${mac_filter}   ${mac_filter["AP_Mac"]}  
    ${macFilterEn}    Set Variable If   "macFilterEn" in ${mac_filter}   ${mac_filter["macFilterEn"]}  NO
    ${wlMacRule}    Set Variable If   "wlMacRule" in ${mac_filter}   ${mac_filter["wlMacRule"]}    ${1}
    ${macList}    Set Variable If   "macList" in ${mac_filter}   ${mac_filter["macList"]}   ${EMPTY}
    ${macList}    json_Change  ${macList}
    &{data} =  Create Dictionary
    ...  mac=${AP_Mac}
    ...  macFilterEn=${macFilterEn}
    #wlMacRule值1为白名单，2为黑名单
    ...  wlMacRule=${wlMacRule} 
    ...  macList=${macList}
    @{data} =  Create List  ${data}

    ${ret}  restful_api  ${set_mac_filter}  ${post}  @{data}  TK=${login_TK}
    Check_Return_Value  ${ret}  true 

在信息监控-设备监控-AP查看SSID配置是否正确
    [Arguments]  &{wifi}
    ${AP_Mac}    Set Variable If   "AP_Mac" in ${wifi}   ${wifi["AP_Mac"]}  
    ${ssid}    Set Variable If   "ssid" in ${wifi}   ${wifi["ssid"]}  ${ssid}
    ${flag}    Set Variable If   "flag" in ${wifi}   ${wifi["flag"]}  true
    ${wifimode}    Set Variable If   "wifimode" in ${wifi}   ${wifi["wifimode"]}  2.4g
    &{data} =  Create Dictionary
    ...  mac=${AP_Mac}
    @{data} =  Create List  ${data}
    ${ret}  Run Keyword IF  '${wifimode}' == '2.4g'  restful_api  ${get_wifi_info_2g}  ${post}  @{data}  TK=${login_TK}
    ...  ELSE   restful_api  ${get_wifi_info_5g}  ${post}  @{data}  TK=${login_TK}
    check_regexp_result  "ssidName":"${ssid}","ssidCrypto":"OPEN"  ${ret}   ${flag}

在信息监控-设备监控-AP查看MAC过滤功能是否正确
    [Arguments]  &{wifi}
    ${AP_Mac}    Set Variable If   "AP_Mac" in ${wifi}   ${wifi["AP_Mac"]}  
    ${macFilterEn}    Set Variable If   "macFilterEn" in ${wifi}   ${wifi["macFilterEn"]}  NO
    ${maclist}    Set Variable If   "maclist" in ${wifi}   ${wifi["maclist"]}   NO
    ${wlMacRule}    Set Variable If   "wlMacRule" in ${wifi}   ${wifi["wlMacRule"]}   NO
    &{data} =  Create Dictionary
    ...  mac=${AP_Mac}
    @{data} =  Create List  ${data}
    ${ret}  restful_api  ${get_mac_filter}  ${post}  @{data}  TK=${login_TK}  
    check_regexp_result  "macFilterEn":"${macFilterEn}"  ${ret}   
    Run Keyword IF  '${maclist}' == 'NO'    check_regexp_result  "macList":\\[\\]  ${ret} 
    ...  ELSE           check_regexp_result  "macList":\\[{"mac":"${maclist}","name":""}\\]  ${ret} 

    Run Keyword IF  '${wlMacRule}' == '1'    check_regexp_result  "wlMacRule":"1"  ${ret} 
    ...  ELSE IF   '${wlMacRule}' == '2'     check_regexp_result  "wlMacRule":"2"  ${ret}
    ...  ELSE       check_regexp_result  "wlMacRule":  ${ret}   false